package com.wswy.wzcx.ui.fkdj

import android.text.TextUtils
import com.wswy.wzcx.utils.StringUtils
import java.math.BigDecimal

class FineData(private val _fromQuery :Boolean= false) {

    var fineNo:String?=null

    var fineName:String?=null

    var fineDate:String?=null

    var carNo:String?=null

    var photo:String?=null

    var couponId:Long = 0

    var payStyle = 20

    private var fineFeeText:CharSequence?=null

    var fineFee = BigDecimal.ZERO.setScale(2, BigDecimal.ROUND_HALF_UP)
    private set

    var serviceFee = BigDecimal.ZERO.setScale(2, BigDecimal.ROUND_HALF_UP)
    private set


    var lateFee = BigDecimal.ZERO.setScale(2, BigDecimal.ROUND_HALF_UP)
    private set

    var quickFee = BigDecimal.ZERO.setScale(2, BigDecimal.ROUND_HALF_UP)
    private set

    //优惠卷
    var couponFee = BigDecimal.ZERO.setScale(2, BigDecimal.ROUND_HALF_UP)
    private set

    var totalFee = BigDecimal.ZERO.setScale(2, BigDecimal.ROUND_HALF_UP)
    private set



    /**
     * 罚款金额
     * @param num
     */
    fun setFineFee(num: CharSequence?) {

        fineFeeText = num

        fineFee = StringUtils.parseToMoney(num)

        //可能是0元单
        if (!hasFineFee()){
            setLateFee("0")
            setServiceFee("0")
        }
    }

    /**
     * 滞纳金
     * @param num
     */
    fun setLateFee(num: String?) {

        lateFee = StringUtils.parseToMoney(num)
    }


    /**
     * 服务费
     */
    fun setServiceFee(num: String?) {

        serviceFee = StringUtils.parseToMoney(num)
    }


    /**
     * 极速办理
     */
    fun setQuickFee(num: String?){

        quickFee = StringUtils.parseToMoney(num)
    }

    /**
     * 优惠券金额
     */
    fun setCouponFee(num: String?){
        couponFee = StringUtils.parseToMoney(num)
    }

    fun getQuickFeeText() = quickFee.toPlainString()

    fun getServiceFeeText() = serviceFee.add(quickFee).toString()

    fun getFineFeeText() = fineFee.toPlainString()

    fun getTotalFeeText() : String {
        val total = fineFee.add(serviceFee).add(lateFee).add(quickFee)
        if (total.toFloat() > 0 && couponFee.toFloat() > 0){
            //如果有优惠券和填了处罚金额
            return total.minus(couponFee).toString()
        }

        return total.toString()
    }

    fun fromQuery() = _fromQuery

    fun hasFineFee() = !TextUtils.isEmpty(fineFeeText)

    fun hasQuickFee() = quickFee.toFloat() > 0f

    fun hasCouponFee() = couponFee.toFloat() > 0

}